home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-01 | 23.6 KB | 850 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UObject.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- // MacApp
-
- // MacApp
- //The following installed by CKopala 6/23/96
- //Doesn't compile for 68K without it.
- #if qDebug || qTheDebugger && !qPowerPC
- #ifndef __UCLASSDESCITERATOR__
- #include "UClassDescIterator.h"
- #endif
-
- #ifndef __MEMORYHEAP__
- #include "MemoryHeap.h"
- #endif
-
- #ifndef __BESTFITHEAP__
- #include "BestFitHeap.h"
- #endif
-
- #ifndef __OBJECTHEAP__
- #include "ObjectHeap.h"
- #endif
- #endif
-
- #if qDebug || qTheDebugger
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
- #endif
-
- #ifndef __UDEPENDENCIES__
- #include "UDependencies.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #if qDebug || qTheDebugger
- #ifndef __UTHEDEBUGGER__
- #include "UTheDebugger.h"
- #endif
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- // Voodoo Monkey
-
- #if qInspector
- #ifndef __NUBINSPECTORHOOKS__
- #include "NubInspectorHooks.h"
- #endif
- #endif
-
- //BEGIN Added by C Kopala 6/14/96
- #if qDebug
- long gObjectCount = 0;
- Boolean gObjectCountingEnabled = FALSE;
- Boolean gPrintBaseClassInfo = FALSE;
- Boolean gPrintMacAppClassInfo = FALSE;
- Boolean gPrintAppClassInfo = FALSE;
- Boolean gAppUserFlag1 = FALSE;
- Boolean gAppUserFlag2 = FALSE;
- Boolean gAppUserFlag3 = FALSE;
- #endif
- //END Added by C Kopala 6/14/96
-
- #ifndef qMacApp
- #define qMacApp FALSE
- #endif
-
- //----------------------------------------------------------------------------------------
- // Globals
- //----------------------------------------------------------------------------------------
-
- // pObjectAllocationFlag is set to true in TObject::TObject, and set back to false in
- // TObject::IObject and TObject::ReadFrom. This is used to warn the programmer that forgets
- // to call TObject::IObject or TObject::ReadFrom. Forgetting this means the inspector won't
- // know about the object.
-
- #if qInspector
- static Boolean pObjectAllocationFlag;
- static TObject* pLastObject;
- #endif
-
-
- //========================================================================================
- // CLASS TObject
- //========================================================================================
- #undef Inherited
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M0(TObject);
-
- //----------------------------------------------------------------------------------------
- // TObject::operator new:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- void* TObject::operator new(size_t size)
- {
- return MAOperatorNew(size);
- }
-
- //----------------------------------------------------------------------------------------
- // TObject::operator delete:
- //----------------------------------------------------------------------------------------
- #pragma segment Main
-
- void TObject::operator delete(void* obj)
- {
- MAOperatorDelete(obj);
- }
-
- //----------------------------------------------------------------------------------------
- // TObject::TObject:
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TObject::TObject()
- {
- #if qInspector
- if (pObjectAllocationFlag)
- {
- CStr255 message;
-
- if ( IsObject(pLastObject) )
- pLastObject->GetClassName(message);
- else
- message = "Someone";
-
- message += " forgot to call IObject or ReadFrom!";
-
- fprintf(stderr, "%s\n", (char*)message);
- }
-
- pObjectAllocationFlag = TRUE; // set the flag
- pLastObject = this;
- #endif
-
- #if qDebug
- if (gPrintBaseClassInfo)
- fprintf(stderr, " >>TObject constructor\n");
- IncrementObjectCount();
- #endif
-
- } // TObject::TObject
-
- //----------------------------------------------------------------------------------------
- // TObject destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TObject::~TObject()
- {
- #if qDebug
- if (gPrintBaseClassInfo)
- fprintf(stderr, " >>TObject destructor\n");
- DecrementObjectCount();
- #endif
- }
-
- //BEGIN Added by C Kopala 6/14/96
- #if qDebug
- //----------------------------------------------------------------------------------------
- // TObject::PrintConstructorClassInfo
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- void TObject::PrintConstructorClassInfo()
- {
- ClassName theClassName;
- ClassID theClassId;
- size_t theClassSize;
-
- if (gPrintMacAppClassInfo)
- {
- this -> GetClassName(theClassName);
- theClassId = this -> GetClassID();
- theClassSize = this -> GetClassSize();
- fprintf(stderr, "Construct %s", (char*)theClassName);
- fprintf(stderr, "@ %p", this);
- fprintf(stderr, " Id=%d", theClassId);
- fprintf(stderr, " Size=%d", theClassSize);
-
- if (gObjectCountingEnabled && gPrintMacAppClassInfo)
- PrintObjectCount();
-
- fprintf(stderr, "\n");
- }
-
- }
- #endif
-
- #if qDebug
- //----------------------------------------------------------------------------------------
- // TObject::PrintDestructorClassInfo
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- void TObject::PrintDestructorClassInfo()
- {
- ClassName theClassName;
- ClassID theClassId;
- size_t theClassSize;
-
- if (gPrintMacAppClassInfo)
- {
- this -> GetClassName(theClassName);
- theClassId = this -> GetClassID();
- theClassSize = this -> GetClassSize();
- fprintf(stderr, "Destruct %s", (char*)theClassName);
- fprintf(stderr, "@ %p", this);
- fprintf(stderr, " Id=%d", theClassId);
- fprintf(stderr, " Size=%d", theClassSize);
-
- if (gObjectCountingEnabled)
- PrintObjectCount();
-
- fprintf(stderr, "\n");
- }
-
- }
- #endif
-
- #if qDebug
- //----------------------------------------------------------------------------------------
- // TObject::PrintAppConstructorClassInfo
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- void TObject::PrintAppConstructorClassInfo()
- {
- ClassName theClassName;
- ClassID theClassId;
- size_t theClassSize;
-
- if (gPrintAppClassInfo)
- {
- this -> GetClassName(theClassName);
- theClassId = this -> GetClassID();
- theClassSize = this -> GetClassSize();
- fprintf(stderr, "#Construct %s", (char*)theClassName);
- fprintf(stderr, "@ %p", this);
- fprintf(stderr, " Id=%d", theClassId);
- fprintf(stderr, " Size=%d", theClassSize);
-
- if (gObjectCountingEnabled)
- PrintObjectCount();
-
- fprintf(stderr, "\n");
- }
-
- }
- #endif
-
- #if qDebug
- //----------------------------------------------------------------------------------------
- // TObject::PrintAppDestructorClassInfo
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- void TObject::PrintAppDestructorClassInfo()
- {
- ClassName theClassName;
- ClassID theClassId;
- size_t theClassSize;
-
- if (gPrintAppClassInfo)
- {
- this -> GetClassName(theClassName);
- theClassId = this -> GetClassID();
- theClassSize = this -> GetClassSize();
- fprintf(stderr, "#Destruct %s", (char*)theClassName);
- fprintf(stderr, "@ %p", this);
- fprintf(stderr, " Id=%d", theClassId);
- fprintf(stderr, " Size=%d", theClassSize);
-
- if (gObjectCountingEnabled)
- PrintObjectCount();
-
- fprintf(stderr, "\n");
- }
-
- }
- #endif
-
- //END Added by C Kopala 6/14/96
- //----------------------------------------------------------------------------------------
- // TObject::Hash:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- HashValue TObject::Hash() const
- {
- return (long) this >> 2;
- } // TObject::Hash
-
- //----------------------------------------------------------------------------------------
- // TObject::IsSame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- Boolean TObject::IsSame(const TObject* theObject) const
- {
- return this == theObject;
- } // TObject::IsSame
-
- //----------------------------------------------------------------------------------------
- // TObject::IsEqual:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- Boolean TObject::IsEqual(const TObject* /* theObject */) const
- {
- #if qDebug
- ProgramBreak("You need to override the IsEqual method");
- #endif
-
- return FALSE;
- } // TObject::IsEqual
-
- //----------------------------------------------------------------------------------------
- // TObject::CompareObject:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- ComparisonResult TObject::CompareObject(const TObject* arg) const
- {
- if (this->IsLessThan(arg))
- return kLessThan;
- else
- {
- if (this->IsEqual(arg))
- {
- return kEqual;
- }
- else
- return kGreaterThan;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TObject::IsGreaterThan:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- Boolean TObject::IsGreaterThan(const TObject*) const
- {
- #if qDebug
- ProgramBreak("You need to override the IsGreaterThan method");
- #endif
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TObject::IsLessThan:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- Boolean TObject::IsLessThan(const TObject*) const
- {
- #if qDebug
- ProgramBreak("You need to override the IsLessThan method");
- #endif
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TObject::Changed:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::Changed(ChangeID theChange,
- TObject* changedBy)
- {
- TDependencySpace* itsDependencySpace = this->GetDependencySpace();
- if (itsDependencySpace)
- itsDependencySpace->NotifierChanged(this,theChange,changedBy);
- } // TObject::Changed
-
- //----------------------------------------------------------------------------------------
- // TObject::DoUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::DoUpdate(ChangeID /* theChange */,
- TObject* /* changedObject */,
- TObject* /* changedBy */,
- TDependencySpace* /* dependencySpace */)
- {
- } // TObject::DoUpdate
-
- //----------------------------------------------------------------------------------------
- // TObject::GetDependencySpace:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- TDependencySpace* TObject::GetDependencySpace()
- {
- return gMacAppDependencies;
- }
-
- //----------------------------------------------------------------------------------------
- // TObject::AddDependent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::AddDependent(TObject* dependent)
- {
- TDependencySpace* itsDependencySpace = this->GetDependencySpace();
- if (itsDependencySpace)
- itsDependencySpace->AddDependency(this, dependent, kNoLabel);
- } // TObject::AddDependent
-
- //----------------------------------------------------------------------------------------
- // TObject::RemoveDependent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::RemoveDependent(TObject* dependent)
- {
- TDependencySpace* itsDependencySpace = this->GetDependencySpace();
- if (itsDependencySpace)
- itsDependencySpace->RemoveDependency(this, dependent, kNoLabel);
- } // TObject::RemoveDependent
-
- //----------------------------------------------------------------------------------------
- // TObject::RemoveAllDependencies:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::RemoveAllDependencies()
- {
- TDependencySpace* itsDependencySpace = this->GetDependencySpace();
- if (itsDependencySpace)
- itsDependencySpace->RemoveDependencies(this); // Call the routine in UDependencies
- } // TObject::RemoveAllDependencies
-
- //----------------------------------------------------------------------------------------
- // TObject::RemoveDependenciesOnFree:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- Boolean TObject::RemoveDependenciesOnFree()
- {
- return TRUE; // By default we always assume we might have dependents
- } // TObject::RemoveDependenciesOnFree
-
- //----------------------------------------------------------------------------------------
- // TObject::IsMarked:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- Boolean TObject::IsMarked()
- {
- return FALSE;
- } // TObject::IsMarked
-
- //----------------------------------------------------------------------------------------
- // TObject::SetMark:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::SetMark(Boolean /* state */)
- {
- } // TObject::SetMark
-
- //----------------------------------------------------------------------------------------
- // TObject::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- TObject* TObject::Clone()
- {
-
-
- return this->ShallowClone();
- } // TObject::Clone
-
- //----------------------------------------------------------------------------------------
- // TObject::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TObject::GetStandardSignature()
- {
- return (this->GetClassDescDynamic())->GetSignature();
- } // TObject::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TObject::ReadFrom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TObject::ReadFrom(TStream* /* aStream */)
- {
- #if qDebug || qSym
- fClassID = this->GetClassID();
- #endif
-
- #if qInspector
- pObjectAllocationFlag = FALSE; // clear the flag
- pLastObject = NULL;
- #endif
-
- #if qTheDebugger
- TheDbgr_Add_Object(this);
- #endif
-
- #if qInspector
- if ( NubIsInstalled() )
- {
- ClassName name;
-
- this->GetClassName(name);
- NubNewObject(this, name);
- }
- #endif
- } // TObject::ReadFrom
-
- //----------------------------------------------------------------------------------------
- // TObject::WriteTo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TObject::WriteTo(TStream* /* aStream */)
- {
- } // TObject::WriteTo
-
- //----------------------------------------------------------------------------------------
- // TObject::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::Free()
- {
- if (this->RemoveDependenciesOnFree())
- this->RemoveAllDependencies();
-
- this->ShallowFree();
- } // TObject::Free
-
- //----------------------------------------------------------------------------------------
- // TObject::GetClassName:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::GetClassName(ClassName& clName) const
- {
- clName = (this->GetClassDescDynamic())->GetClassName();
- } // TObject::GetClassName
-
- //----------------------------------------------------------------------------------------
- // TObject::GetClassID:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- ClassID TObject::GetClassID() const
- {
- return (this->GetClassDescDynamic())->GetClassID();
- } // TObject::GetClassID
-
- //----------------------------------------------------------------------------------------
- // TObject::GetClassSize:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- size_t TObject::GetClassSize()
- {
- return (this->GetClassDescDynamic())->GetClassSize();
- } // TObject::GetClassSize
-
- //----------------------------------------------------------------------------------------
- // TObject::GetSuperClass:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- const ClassDesc* TObject::GetSuperClass()
- {
- return (this->GetClassDescDynamic())->GetBaseClass();
- } // TObject::GetSuperClass
-
- //----------------------------------------------------------------------------------------
- // TObject::IObject:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::IObject()
- {
- #if qDebug || qSym
- fClassID = this->GetClassID();
- #endif
-
- #if qInspector
- pObjectAllocationFlag = FALSE; // clear the flag
- pLastObject = NULL;
- #endif
-
- #if qTheDebugger
- TheDbgr_Add_Object(this);
- #endif
-
- #if qInspector
- if ( NubIsInstalled() )
- {
- ClassName name;
-
- this->GetClassName(name);
- NubNewObject(this, name);
- }
- #endif
- } // TObject::IObject
-
- //----------------------------------------------------------------------------------------
- // TObject::IsSameClass:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- Boolean TObject::IsSameClass(const ClassDesc* classDesc)
- {
- return this->GetClassDescDynamic() == classDesc;
- } // TObject::IsSameClass
-
- //----------------------------------------------------------------------------------------
- // TObject::DescendsFrom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- Boolean TObject::DescendsFrom(const ClassDesc* classDesc) const
- {
- return (this->GetClassDescDynamic())->DescendsFrom(classDesc);
- } // TObject::DescendsFrom
-
- //----------------------------------------------------------------------------------------
- // TObject::ShallowClone:
- //----------------------------------------------------------------------------------------
- #pragma segment MANonRes
-
- TObject* TObject::ShallowClone()
- {
- TObject * result = (TObject *) operator new (this->GetClassSize());
- MABlockMove(this, result, this->GetClassSize());
-
- #if qTheDebugger
- TheDbgr_Add_Object(result);
- #endif
-
- #if qInspector
- if ( NubIsInstalled() )
- {
- ClassName name;
-
- this->GetClassName(name);
- NubNewObject(this, name);
- }
- #endif
-
- #if qDebug
- //This section added by C. Kopala 6/30/96
- IncrementObjectCount();
- if (gPrintAppClassInfo)
- {
- ClassName theClassName;
- ClassID theClassId;
- size_t theClassSize;
- this -> GetClassName(theClassName);
- theClassId = this -> GetClassID();
- theClassSize = this -> GetClassSize();
- fprintf(stderr, " >>Cloned %s", (char*)theClassName);
- fprintf(stderr, "@ %p", result);
- fprintf(stderr, " Id=%d", theClassId);
- fprintf(stderr, " Size=%d", theClassSize);
-
- if (gObjectCountingEnabled)
- PrintObjectCount();
-
- fprintf(stderr, "\n");
- }
- #endif
-
- return result;
- } // TObject::ShallowClone
-
- //----------------------------------------------------------------------------------------
- // TObject::ShallowFree:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::ShallowFree()
- {
- #if qTheDebugger
- TheDbgr_Delete_Object(this);
- #endif
-
- #if qInspector
- if ( NubIsInstalled() )
- {
- ClassName name;
-
- this->GetClassName(name);
- NubObjectFreed(this, name);
- }
- #endif
-
- delete this;
- } // TObject::ShallowFree
-
- //----------------------------------------------------------------------------------------
- // TObject::SubClassResponsibility:
- //----------------------------------------------------------------------------------------
- #pragma segment MAObjectRes
-
- void TObject::SubClassResponsibility()
- {
- #if qDebug
- ClassName s;
- #endif
-
- #if qDebugMsg
- GetCallersMethodName(s);
-
- fprintf(stderr, "%s: must be overridden!", (char *) s);
- #endif
- } // TObject::SubClassResponsibility
-
- //----------------------------------------------------------------------------------------
- //BEGIN Added by C Kopala 6/14/96
- #if qDebug
- //----------------------------------------------------------------------------------------
- // IncrementObjectCount
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalRes
- void IncrementObjectCount()
- {
- if (gObjectCountingEnabled)
- gObjectCount++;
- }
- //----------------------------------------------------------------------------------------
- // DecrementObjectCount
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalRes
- void DecrementObjectCount()
- {
- if (gObjectCountingEnabled)
- gObjectCount--;
- }
- //----------------------------------------------------------------------------------------
- // PrintObjectCount
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalRes
- void PrintObjectCount()
- {
- if (gObjectCountingEnabled)
- fprintf(stderr, " ObjCnt = %d", gObjectCount);
- }
- //----------------------------------------------------------------------------------------
- // DumpClassInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalRes
- void DumpClassInfo()
- {
- MA_ClassReference aClassDesc;
- CClassIterator iter;
-
- for (aClassDesc = iter.FirstClassDesc(); iter.More(); aClassDesc = iter.NextClassDesc())
- {
- ClassName theClassName = aClassDesc -> GetClassName();
- ClassID theClassId = aClassDesc -> GetClassID();
- size_t theClassSize = aClassDesc -> GetClassSize();
-
- fprintf(stderr, " %s", (char*)theClassName);
- fprintf(stderr, " classId = %d", theClassId);
- fprintf(stderr, " classSize = %d", theClassSize);
- fprintf(stderr, "\n");
- }
- }
- //----------------------------------------------------------------------------------------
- // DisplayMemoryInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalRes
- void DisplayMemoryInfo()
- {
- long availableMemory = 0;
- long heapSize = 0;
- Size tempSize = 0;
- Size szTemporaryReserve;
- Size szMemReserve;
-
- GetReserveSize(szTemporaryReserve,szMemReserve);
-
- availableMemory = gObjectHeap -> BytesFree();
- heapSize = gObjectHeap -> HeapSize();
- unsigned long freeMemory = FreeMem();
-
- fprintf(stderr, " heapSize = %d", heapSize);
- fprintf(stderr, " availableMemory = %d", availableMemory);
- fprintf(stderr, " used = %d", heapSize - availableMemory);
- fprintf(stderr, "\n");
- fprintf(stderr, " freeMemory = %d", freeMemory);
- fprintf(stderr, "\n");
- fprintf(stderr, " szTemporaryReserve = %d", szTemporaryReserve);
- fprintf(stderr, " szMemReserve = %d", szMemReserve);
- fprintf(stderr, "\n");
- fprintf(stderr, "\n");
- }
- //----------------------------------------------------------------------------------------
- // InitUDebugGlobals
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalRes
- void InitUDebugGlobals()
- {
- gObjectCount = 0;
- gObjectCountingEnabled = FALSE;
- gPrintBaseClassInfo = FALSE;
- gPrintMacAppClassInfo = FALSE;
- gPrintAppClassInfo = FALSE;
- gAppUserFlag1 = FALSE;
- gAppUserFlag2 = FALSE;
- gAppUserFlag3 = FALSE;
- }
- #endif
- //END Added by C Kopala 6/14/96
- //----------------------------------------------------------------------------------------
- // End of UObject.cp
-
- #pragma segment Inline
-